import { BaseWindow } from "../../../../component/window/BaseWindow";
import { IWareHouseSellWindow } from "../../../../../modules/interfaces/IWareHouseSellWindow";
import { Language } from "../../../../../extend/language/Language";
import { GTabBar } from "../../../../../com/mui/controls/GTabBar";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { MuiEvent } from "../../../../../com/mui/events/MuiEvent";
import { WareHouseSellGoodsPanel } from "./WareHouseSellGoodsPanel";
import { WareHouseSelfGoodsPanel } from "./WareHouseSelfGoodsPanel";
import { GameController } from "../../../mvc/GameController";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { EPrictUnit } from "../../../../../Message/Public/EPrictUnit";
import { Cache } from "../../../cache/Cache";
import { ItemData } from "../../../resource/info/ItemData";
type int = number;
//class WareHouseSellWindow
    
    export  class WareHouseSellWindow extends BaseWindow implements IWareHouseSellWindow
    {
        constructor()
        {
            super();
            setSize(310, 370);
            title = Language.getString(57631);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._tabBar = new GTabBar();
            this._tabBar.x = 16;
            this._tabBar.y = 34;
            this._tabBar.horizontalGap = 2;
            this._tabBar.buttonWidth = 70;
            this._tabBar.buttonFilters = [FilterConst.glowFilter];
            this._tabBar.dataProvider = Language.getArray(57632);
            this._tabBar.selectedIndex = 0;
            this._tabBar.addEventListener(MuiEvent.GTABBAR_SELECTED_CHANGE, this.onTabBarSelectedChangeHandler);
            addChild(this._tabBar);
            this._sellGoods = new WareHouseSellGoodsPanel();
            this._sellGoods.x = 18;
            this._sellGoods.y = 60;
            addChild(this._sellGoods);
            this._selfGoods = new WareHouseSelfGoodsPanel();
            this._selfGoods.x = 18;
            this._selfGoods.y = 60;
            return;
        }

        /* internal  */onTabBarSelectedChangeHandler(arg1: MuiEvent): void
        {
            this.removePanel();
            var loc1=this._tabBar.selectedIndex;
            switch (loc1) 
            {
                case 0:
                {
                    this._sellGoods.updateMoney(this._warehouseGold, this._warehouseCoin);
                    addChild(this._sellGoods);
                    if (!GameController.pack.view.isHide) 
                    {
                        GameController.pack.view.hide();
                    }
                    break;
                }
                case 1:
                {
                    addChild(this._selfGoods);
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildWareHouseSelfGoods, false));
                    break;
                }
            }
            return;
        }

        /* internal  */removePanel(): void
        {
            if (this._sellGoods && this._sellGoods.parent) 
            {
                removeChild(this._sellGoods);
            }
            else if (this._selfGoods && this._selfGoods.parent) 
            {
                removeChild(this._selfGoods);
            }
            return;
        }

        public updateMoney(arg1: Map<any, any> /* flash.utils.Dictionary */): void
        {
            if (arg1) 
            {
                this._warehouseGold = arg1[EPrictUnit._EPriceUnitGold];
                this._warehouseCoin = arg1[EPrictUnit._EPriceUnitCoin];
                if (this._sellGoods) 
                {
                    this._sellGoods.updateMoney(this._warehouseGold, this._warehouseCoin);
                }
            }
            return;
        }

        public resetWindow(): void
        {
            if (this._sellGoods && this._sellGoods.parent) 
            {
                this._sellGoods.resetPanel();
            }
            return;
        }

        public updateSelfGoods(): void
        {
            if (this._tabBar.selectedIndex != 1) 
            {
                this.removePanel();
                addChild(this._selfGoods);
                this._tabBar.selectedIndex = 1;
            }
            if (Cache.instance.pack.wareHousePackCache.sSeqMarketItemSell != null) 
            {
                this._selfGoods.updateDataProvider(Cache.instance.pack.wareHousePackCache.sSeqMarketItemSell.marketItems);
            }
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this.removePanel();
            addChild(this._sellGoods);
            this._tabBar.selectedIndex = 0;
            this._sellGoods.resetPanel();
            Dispatcher.dispatchEvent(new DataEvent(EventName.MarketSellWindowStateChange, true));
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            Dispatcher.dispatchEvent(new DataEvent(EventName.MarketSellWindowStateChange, false));
            return;
        }

        public get curSelectedIndex(): int
        {
            if (this._tabBar != null) 
            {
                return this._tabBar.selectedIndex;
            }
            return 0;
        }

        public setSellGoodsItem(arg1: ItemData): void
        {
            if (this._tabBar.selectedIndex != 0) 
            {
                this.removePanel();
                addChild(this._sellGoods);
                this._tabBar.selectedIndex = 0;
            }
            this._sellGoods.setItemData(arg1);
            return;
        }

        /* internal */ /* var */_tabBar: GTabBar;

        /* internal */ /* var */_sellGoods: WareHouseSellGoodsPanel;

        /* internal */ /* var */_selfGoods: WareHouseSelfGoodsPanel;

        /* internal */ /* var */_warehouseGold: int;

        /* internal */ /* var */_warehouseCoin: int;
    }
